//
//  ProcessPictureHeader.swift
//  QualityControlSystem
//
//  Created by dundun on 17/1/23.
//  Copyright © 2017年 com.mask. All rights reserved.
//

import UIKit
import SnapKit

class ProcessPictureHeader: UICollectionReusableView {
    
    var headerLabel: UILabel?
    var headerClickedBlock: ( (_ isShowText: Bool) -> Void)?
    
    var isShow: Bool? {
        didSet {
            if isShow == true {
                headerLabel?.numberOfLines = 0
            } else {
                headerLabel?.numberOfLines = 1
            }
        }
    }
    
    var headerText: String? {
        didSet {
            headerLabel?.text = headerText
        }
    }
    
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        setupSubviews()
        backgroundColor = UIColor.red
        isShow = false
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    func setupSubviews() {
        headerLabel = UILabel()
        headerLabel?.isUserInteractionEnabled = true
        headerLabel?.textAlignment = .left
        headerLabel?.textColor = Color.textMedium
        headerLabel?.font = UIFont.systemFont(ofSize: 15.0)
        addSubview(headerLabel!)
        headerLabel?.snp.makeConstraints({ (make) in
            make.top.bottom.equalTo(self)
            make.left.equalTo(self).offset(Padding.left)
            make.right.equalTo(self).offset(-Padding.left)
        })
        
        let tap = UITapGestureRecognizer(target: self, action: #selector(headerClicked(tap:)))
        addGestureRecognizer(tap)
    }
    
    func headerClicked(tap: UITapGestureRecognizer) {
        if isShow == true {
            isShow = false
        } else {
            isShow = true
        }
        headerClickedBlock!(isShow!)
    }

}
